package cn.stockinclient.controller;

import cn.stockinclient.Client.StockInClient;
import cn.stockinclient.model.StockIn;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@AllArgsConstructor
@RestController
@Slf4j
public class StockInController {
    @Qualifier("cn.stockinclient.Client.StockInClient")
    @Autowired
    private final StockInClient stockInClient;

    /**
     * 根据入库单id查询
     */
    @GetMapping("/findByStockInId/{stockInId}")
    public StockIn findByStockInId(@PathVariable Long stockInId){
        StockIn stockIn = stockInClient.findByStockInId(stockInId);
        log.info("--------------In client  findByStockInId---------------------");
        return stockIn;
    }

    /**
     * 查询所有入库单
     */
    @GetMapping("/queryAllStockIn")
    public List<StockIn> queryAllStockIn(){
        List<StockIn> StockInList = stockInClient.queryAllStockIn();
        log.info("--------------In client  queryAllStockIn---------------------");
        return StockInList;
    }

    /**
     * 根据入库单id删除
     */
    @DeleteMapping("/deleteStockIn/{stockInId}")
    public boolean deleteStockIn(@PathVariable Long stockInId){
        boolean result = stockInClient.deleteStockIn(stockInId);
        log.info("--------------In client  deleteStockIn---------------------");
        return result;
    }

    /**
     * 新增入库单
     */
    @PostMapping("/addNewStockIn")
    public boolean addNewStockIn(@RequestBody StockIn stockIn){
        boolean result = stockInClient.addNewStockIn(stockIn);
        log.info("--------------In client  addNewStockIn---------------------");
        return result;
    }

    /**
     * 修改入库单
     */
    @PutMapping("/updateStockIn")
    public boolean updateStockIn(@RequestBody StockIn stockIn){
        boolean result = stockInClient.updateStockIn(stockIn);
        log.info("--------------In client  updateStockIn---------------------");
        return result;
    }
}
